<?php

namespace Home\Controller;
use Home\Core\CommandSDK;
use Think\Controller;
class HttpController extends Controller
{
    const POST = 'POST';
    protected $code = null;
    protected $return = null;
    protected $base = null;
    protected $key = null;
    protected $param = null;
    protected $method = null;
    protected $sdk = null;

    public function __construct()
    {
        parent::__construct();
        $this->sdk = $_sdk = new CommandSDK();
        $this->base = $_sdk::BASE;
        $this->key = $this->sdk->getKey();
    }

    public function http_request($api,$_param,$_method = 'POST'){
        $this->method = $_method;
        $this->param = $_param;
        $this->param['msgid'] = $api;
        $this->formatParam();
        if($this->method == self::POST){
//            $this->param  = json_encode($this->param);
            list($this->code,$this->return) = post($this->base,$this->param);
        }else{
            list($this->code,$this->return) = get($this->base,$this->param);
        }
        return json_decode($this->return);//json_decode是json解密的相关的函数
    }
    protected function formatParam(){
        return $this->param['authkey'] = $this->key;
    }

}